<template>
  <div id="app">
    <div class="box">
      <div class="item">
        <h3>欢迎光临_vue开发的手印系统_水果店</h3>
      </div>
      <div class="item">苹果{{price}}¥/斤,折扣'({{discount}}折)'</div>
      <div class="item">
        请输入你要购买的斤数
        <input type="number" v-model="num" />
      </div>
      <div class="item">
        <button @click="onClick">结账买单</button>
      </div>
      <div class="item">结账单:总价{{total}}元 折后价:{{disTotal}}元 省了{{sub}}元</div>
    </div>
    <div class="box">
      <h2>兴趣爱好</h2>
      <div class="check">
        <!-- <input type="checkbox" v-for="(item,index) in like" :key="index" :v-model="item"> -->
        <span v-for="(item,index) in like" :key="index">
          <input type="checkbox" :value="item" v-model="checkArr" />
          {{item}}
        </span>
        <ul>
          <li v-for="(item,index) in checkArr" :key="index">{{item}}</li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      price: 10,
      discount: 8,
      num: 0,
      total: 0,
      disTotal: 0,
      sub: 0,
      like: ["科幻", "喜剧", "动漫", "冒险", "科技", "军事", "娱乐", "奇闻"],
      checkArr: []
    };
  },
  methods: {
    onClick() {
      this.total = this.price * this.num;
      this.disTotal = (this.discount / 10) * this.total;
      this.sub = this.total - this.disTotal;
      
    }
  },
  created() {},
  mounted() {}
};
</script>

<style scoped>
#app {
  margin-top: 25px;
}
.box {
  border: 1px solid #ccc;
}
.item {
  border: 1px solid #ccc;
  display: flex;
  justify-content: center;
  align-items: center;
}
.box:nth-child(2) {
  margin-top: 35px;
}
</style>